package com.summer.core.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.ServletContext;

import org.springframework.stereotype.Service;

import com.cxl.autocode.create.AutoSummerCode;
import com.cxl.autocode.data.SmrFrameInSamePackageImpl;
import com.summer.core.autocode.AutoCodeCreate;
import com.summer.core.dao.TableDao;
import com.summer.core.entity.Field;
import com.summer.core.entity.STable;
import com.summer.core.service.TableService;
import com.summer.core.xml.parser.TableParser;

/**
 * 表service实现 
 * @author wwwlike
 *
 */
@Service
public class TableServiceImpl extends BaseServiceImpl<STable, String, TableDao>
		implements TableService {

	@Resource
	public void setDao(TableDao dao) {
		this.dao = dao;
	}

	public List<STable> getExitsTable() {
	
		return dao.getAll();
		
	}

	public List<String> getImportTableNames() {
		List<String> all=TableParser.parseXml();
		List<STable> exist=getExitsTable();
		List<String> importList=new ArrayList<String>();
		for(int i=0;i<all.size();i++)
		{
			boolean has=false;
				for(STable table:exist)
				{
				if(table.getClassName().equals(all.get(i)))
				{
					has=true;
				}
				}
			
			if(!has)
			{
				importList.add(all.get(i));
			}
		}
		return importList;
	}

	public void createCode(ServletContext Context,STable table) {
		AutoCodeCreate create=new AutoSummerCode();
		create.createCode(Context,table, new SmrFrameInSamePackageImpl(table));
		List<Field> fields=get(table.getId()).getField();
		create.createJsp(Context,table, fields);
	}
	
}
